﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using JobManager;

namespace JobService
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://emlynoregan.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string Create(string aUserID)
        {
            Job ljob = new Job(aUserID);

            return ljob.JobID;
        }

        [WebMethod]
        public JobStatus GetStatus(string aUserID, string aJobID)
        {
            JobStatus retval = JobStatus.NotExist;

            if (Job.Exists(aUserID, aJobID))
            {
                Job ljob = new Job(aUserID, aJobID);

                retval = ljob.Status;
            }

            return retval;
        }

        [WebMethod]
        public string GetStatusMessage(string aUserID, string aJobID)
        {
            string retval = null;

            if (Job.Exists(aUserID, aJobID))
            {
                Job ljob = new Job(aUserID, aJobID);

                retval = ljob.StatusMessage;
            }

            return retval;
        }

        [WebMethod]
        public void SubmitForProcessing(string aUserID, string aJobID)
        {
            if (Job.Exists(aUserID, aJobID))
            {
                Job ljob = new Job(aUserID, aJobID);

                ljob.SubmitForProcessing();
            }
            else
                throw new Exception("No such Job");
        }

        [WebMethod]
        public void Cancel(string aUserID, string aJobID)
        {
            if (Job.Exists(aUserID, aJobID))
            {
                Job ljob = new Job(aUserID, aJobID);

                ljob.CancelJob();
            }
            else
                throw new Exception("No such Job");
        }
    }
}
